package com.wangy.sct.serviceauth.app.service;

import com.wangy.sct.common.core.SctEnum;
import com.wangy.sct.common.core.SctRuntimeException;
import com.wangy.sct.serviceauth.api.UserInfo;
import com.wangy.sct.serviceauth.app.mapper.UserInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * ClassName: AuthService <br/>
 * Description:  <br/>
 *
 * @author wangyue
 * @version V1.0.0
 * @date 2018/11/20 6:31 PM
 */
@Slf4j
@Service
public class AuthService {

	@Autowired
	private UserInfoMapper userInfoMapper;

	public UserInfo queryById(String userId) {
		com.wangy.sct.serviceauth.app.schema.entity.UserInfo userInfoEntity = null;
		try {
			userInfoEntity = userInfoMapper.findById(userId);
		} catch (Exception e) {
			e.printStackTrace();
			log.error("根据userId查询用户", e);
			throw new SctRuntimeException(SctEnum.UNKNOWEN_EXCEPTION, e);
		}
		if (null == userInfoEntity) {
			throw new SctRuntimeException(SctEnum.USER_NOT_EXIST);
		}
		UserInfo userInfo = new UserInfo();
		BeanCopier beanCopier = BeanCopier.create(com.wangy.sct.serviceauth.app.schema.entity.UserInfo.class, com.wangy.sct.serviceauth.api.UserInfo.class, false);
		beanCopier.copy(userInfoEntity, userInfo, null);
		return userInfo;
	}

}
